<?php
namespace app\admin\controller;
use app\admin\server\AccessToken;
class Index extends Base
{
    protected $token="";

    public function _initialize()
    {
        $AccessToken=new AccessToken();
        $token=$AccessToken::getAccessToken();
        $this->token=$token;
    }

    public function token()
    {
         return $this->token;

    }
    public function creatMenu()
    {
        //组装请求的url地址
        $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=".$this->token;
        $data = array(
            // button下的每一个元素
            "button"=>array(
                //第一个一级菜单
                array('type'=>'click',"name"=>"个人简介","key"=>"info"),
                array(
                    "name"=>"语言排行",
                    "sub_button"=>array(
                        array("name"=>'商品列表',"type"=>"view",
                            'url'=>"http://xiaoziheng.club/home/demo/demo4"),
                        array('name'=>'c/c++','type'=>'pic_sysphoto','key'=>'sysptoto'),
                        array('name'=>'java','type'=>'pic_weixin','key'=>'pic_weixin'),
                        array( "type"=> "pic_photo_or_album",
                                "name"=> "拍照或者相册发图",
                                "key"=> "rselfmenu_1_1",
                                "sub_button"=> [ ])
                    )
                ),
//                array('type'=>'click','name'=>'xxxx','key'=>'content'),
                array(
                    'name'=>'扫码','type'=>'scancode_waitmsg','key'=>'rselfmenu_0_0'
                   )

            )
        );
        //    将数据转换为json格式
        $data = json_encode($data,JSON_UNESCAPED_UNICODE);
        $result = http_curl($url,$data,'post');
        dump($result);
    }

    public function searchMenu()
    {
        $url='https://api.weixin.qq.com/cgi-bin/menu/get?access_token='.$this->token;
        $result = http_curl($url,'post');
        dump($result);
    }

    


}
